package org.wxd.account.engine.user;

import com.google.common.collect.Lists;
import org.wxd.account.api.user.dto.UserMoreInfoRecord;
import org.wxd.account.api.user.dto.UserRecord;
import org.wxd.account.domain.user.User;
import org.wxd.account.domain.user.UserMoreInfo;

import java.util.List;

/**
 * Created by wangxd on 2015/10/30.
 */
public class UserHelper {

    public static List<UserRecord> asUserRecordList(List<User> users){
        List<UserRecord> records = Lists.newArrayList();
        for(User user : users) records.add(asUserRecord(user));
        return records;
    }
    public static UserRecord asUserRecord(User user){
        return UserRecord.newBuilder()
                .userId(user.id())
                .createTime(user.createTime())
                .modifyTime(user.modifyTime())
                .email(user.email())
                .isLock(user.isLock())
                .moreInfo(asUserMoreInfoRecord(user.moreInfo()))
                .build();
    }

    private static UserMoreInfoRecord asUserMoreInfoRecord(UserMoreInfo userMoreInfo) {
        return UserMoreInfoRecord.newBuilder()
                .isActive(userMoreInfo.isActive())
                .name(userMoreInfo.name())
                .type(userMoreInfo.type().toString())
                .build();
    }
}
